
public class Test {

    public static void main(String[] args) {
        Menu menu = new Menu();
        PersonList personList = new PersonList();

        boolean over = false;
        String op;// 储存单行

        // 初始化指令与数量选项对应关系
        MyUtil.init();

        while (!over) {
            op = MyUtil.in.nextLine();
            String[] command = op.split("\\s+");// 将一行字符串分割为指令+多个参数

            switch (command[0]) {
            case "np":
                if (MyUtil.checkMainCommand(command, 0)) {
                    Person tmp_person = Person.newPerson(command[1], command[2], command[3]);
                    if (tmp_person != null) {
                        System.out.println(tmp_person.toString());
                    }
                }
                break;

            case "nd":
                if (MyUtil.checkMainCommand(command, 0)) {
                    menu.addDish(command[1], command[2], command[3], command[4]);
                }
                break;

            case "udd":
                if (MyUtil.checkMainCommand(command, 1)) {
                    menu.changeDish(command[1], command[2], command[3]);
                }
                break;

            case "gd":
                if (MyUtil.checkMainCommand(command, 1)) {
                    if (command[1].equals("-id")) {
                        menu.searchDishByID(command[2]);
                    } else if (command[1].equals("-key")) {
                        if (command.length == 3) {
                            menu.searchDishByKey(command[2]);
                        } else if (command.length == 5) {
                            menu.searchDishByKey(command[2], command[3], command[4]);
                        }
                    }
                }
                break;

            case "pm":
                if (MyUtil.checkMainCommand(command, 0)) {
                    if (command.length == 1) {
                        menu.printAll();
                    } else if (command.length == 3) {
                        menu.printAll(command[1], command[2]);
                    }
                }
                break;

            case "SUDO":
                if (MyUtil.checkMainCommand(command, 0)) {
                    System.out.println(MyUtil.SUDO_IN);
                    SudoCommand.sudoCommand(personList);
                }
                break;

            case "login":
                if (MyUtil.checkMainCommand(command, 1)) {
                    if (command[1].equals("-i")) {
                        personList.loginByID(command[2], command[3]);
                    } else if (command[1].equals("-n")) {
                        personList.loginByName(command[2], command[3]);
                    }
                }
                break;

            case "QUIT":
                if (MyUtil.checkMainCommand(command, 0)) {
                    System.out.println(MyUtil.BYE);
                    System.exit(0);
                }
                break;

            default:
                System.out.println(MyUtil.NO_COMMAND);
                break;
            }
        }
    }
}
